package com.example.buletooth_spp;

import static com.example.buletooth_spp.MainActivity.convertFloatToHalfFloat;

import java.nio.ByteBuffer;

public class SendDataFrame {
    //灯
    private byte lightFlag;
    //风扇转速
    private short fanSpeed;
    //风机转速
    private short rangeHoodSpeed;
    //湿度报警flag
    //燃气报警flag
    //烟雾报警flag
    //温度报警flag
    private byte[] warningOpenFlags = new byte[4];
    //温度报警阈值
    //湿度报警阈值
    //燃气报警阈值
    //烟雾报警阈值
    private float[] warningNums = new float[4];

    public byte[] pack()
    {
        ByteBuffer buffer = ByteBuffer.allocate(32);
        //灯
        buffer.put(lightFlag);
        //风扇转速
        buffer.putShort(fanSpeed);
        //风机转速
        buffer.putShort(rangeHoodSpeed);
        //温度报警flag
        //湿度报警flag
        //燃气报警flag
        //烟雾报警flag
        buffer.put(warningOpenFlags);
        //温度报警阈值
        //湿度报警阈值
        //燃气报警阈值
        //烟雾报警阈值
        buffer.put(convertFloatToHalfFloat(warningNums[0]));
        buffer.put(convertFloatToHalfFloat(warningNums[1]));
        buffer.put(convertFloatToHalfFloat(warningNums[2]));
        buffer.put(convertFloatToHalfFloat(warningNums[3]));

        return buffer.array();
    }

    public byte getLightFlag() {
        return lightFlag;
    }

    public void setLightFlag(byte lightFlag) {
        this.lightFlag = lightFlag;
    }

    public short getFanSpeed() {
        return fanSpeed;
    }

    public void setFanSpeed(short fanSpeed) {
        this.fanSpeed = fanSpeed;
    }

    public short getRangeHoodSpeed() {
        return rangeHoodSpeed;
    }

    public void setRangeHoodSpeed(short rangeHoodSpeed) {
        this.rangeHoodSpeed = rangeHoodSpeed;
    }

    public byte[] getWarningOpenFlags() {
        return warningOpenFlags;
    }

    public void setWarningOpenFlags(byte[] warningOpenFlags) {
        this.warningOpenFlags = warningOpenFlags;
    }

    public float[] getWarningNums() {
        return warningNums;
    }

    public void setWarningNums(float[] warningNums) {
        this.warningNums = warningNums;
    }
}
